/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.everdras.WordFilter;

import java.io.Serializable;
import java.util.Scanner;

/**
 *
 * @author Josh
 */
public class FilteredWord implements Serializable {
    private String orig;
    private String replaceWith;
    
    public FilteredWord(String orig, String replace) {
        this.orig = standardize(orig);
        replaceWith = standardize(replace);
    }
    
    public String getWord() {
        return orig;
    }
    
    public String getReplacement() {
        return replaceWith;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FilteredWord other = (FilteredWord) obj;
        if ((this.orig == null) ? (other.orig != null) : !this.orig.equals(other.orig)) {
            return false;
        }
        if ((this.replaceWith == null) ? (other.replaceWith != null) : !this.replaceWith.equals(other.replaceWith)) {
            return false;
        }
        return true;
    }
    
    private static String standardize(String s) {
        String nu = "";
        Scanner scan = new Scanner(s);
        scan.useDelimiter("");
        
        String cur = null;
        while(scan.hasNext()) {
            cur = scan.next();
            if(cur.equals("_")) {
                nu += " ";
            }
            else {
                nu += cur;
            }
        }
            
        
        
        return nu;
    }
}
